import Header from "../../components/Header.vue";
import Footer from "../../components/Footer.vue";
import Services from "../../components/Services.vue";
import Empty from "../../components/empty.vue";
export default {
  name: "news",
  components: { Header, Footer, Services, Empty },
  data() {
    return {
      currentIndex: 0,
      current: 1,
      total: 0,
      tabsList: [
        {
          src: require("@/assets/images/news1-1.png"),
          activeSrc: require("@/assets/images/news1.png"),
          name: '最新动态',
          type: 'news'
        },
        {
          src: require("@/assets/images/news2.png"),
          activeSrc: require("@/assets/images/news2-1.png"),
          name: '编程赛事',
          type: 'events'
        },
        {
          src: require("@/assets/images/news3.png"),
          activeSrc: require("@/assets/images/news3-1.png"),
          name: '活动通知',
          type: 'notice'
        }
      ],
      pageData: {
        page: 1,
        page_size: 10
      },
      cid: '2',
      newsList: [],
    };
  },
  mounted() {
    this.getNewsList();
  },
  methods: {
    handleTabClick(index) {
      this.currentIndex = index;
      if (index == 0) {
        this.cid = '2';
      } else if (index == 1) {
        this.cid = '4';
      } else if (index == 2) {
        this.cid = '3';
      }
      this.getNewsList();
    },
    handleNewsClick(item) {
      this.$router.push(`/newsDetail?id=${item.id}`);
    },
    // 查询新闻列表
    async getNewsList() {
      const res = await this.$request.get(`api/article/index?cid=${this.cid}&page=${this.pageData.page}&page_size=${this.pageData.page_size}`);
      console.log(res, 'res===');
      if (res.code == 1) {
        this.newsList = res.data.data || [];
        this.total = res.data.total;
      }
    }
  }
};
